<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <?php

//solved the confidencial issue which is open this page in online-crm 
if (!isset($_GET['time']) || !isset($_GET['token']))
	return;

// Verify token first
$privateKey = 'PRIVATEKEY';
$time = $_GET['time'];
$token = $_GET['token'];
$token2 = hash_hmac('sha256', $time, $privateKey);
if ($token != $token2) {
	return;
}

// Check timespan
if (abs(time() - $time) > 5)
	return;

	
//database connection
    $mysql_server_name = "localhost";
    $mysql_username = "root";
    $mysql_password = "";
    $mysql_database = "mc";
    $conn = mysql_connect($mysql_server_name, $mysql_username, $mysql_password) or die("Fail to connect databese:" . $mysql_server_name);
    mysql_select_db($mysql_database) or die("Could not select database");
//select form ID
    $id = $_GET["id"];
    $strsql = "select * from mc_form where form_Id =" . $id;
    $rs = mysql_query($strsql) or die("Query failed");
    $arrayres = mysql_fetch_array($rs);
    ?>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title><?php echo "#" . $arrayres["SurName"] . " " . $arrayres["FirstName"] . " $" . $arrayres["DesiredAmount"]; ?>SACC Form</title>
    </head>
    <body>
        <?php
//open SACC Ttemplate
        $SACCTemplate = $arrayres["viewtemplatepath"];
//choose template directory
        $file = fopen($_SERVER['DOCUMENT_ROOT'] . "/form_view_mc/" . $SACCTemplate, "r");
        while (!feof($file)) {
//$content = fgets($file); 
            $content = str_replace("Form_ID", $arrayres["form_Id"], fgets($file));
            $content = str_replace("CreatedDate", $arrayres["CreatedDate"], $content);
            $content = str_replace("LoanAmount", $arrayres["DesiredAmount"], $content);
            $content = str_replace("PurposeSummary", $arrayres["PurposeSummary"], $content);
//personal information
            $content = str_replace("FirstName", $arrayres["FirstName"], $content);
            $content = str_replace("MiddleName", $arrayres["MiddleName"], $content);
            $content = str_replace("SurName", $arrayres["SurName"], $content);
            $content = str_replace("ClientTitle", $arrayres["Title"], $content);
            $content = str_replace("Residency", $arrayres["Citizenship"], $content);
            $content = str_replace("DateOfBirth", $arrayres["DateBirth"], $content);
            $content = str_replace("DriversLicence", $arrayres["DriverLicense"], $content);
            $content = str_replace("EMailAddress", $arrayres["Email"], $content);
            $content = str_replace("MobileNumber", $arrayres["Mobile"], $content);
            $content = str_replace("HomePhone", $arrayres["HomePhone"], $content);
            $content = str_replace("ResidentialStatus", $arrayres["app_ResidentialStatus"], $content);
            $content = str_replace("NumberofDependant", $arrayres["Dependant"], $content);
            $content = str_replace("StreetNo", $arrayres["StreetNo"], $content);
            $content = str_replace("Street", $arrayres["Street"], $content);
            $content = str_replace("Suburb", $arrayres["Suburb"], $content);
            $content = str_replace("State", $arrayres["State"], $content);
            $content = str_replace("Postcode", $arrayres["PostCode"], $content);
//employment
            $content = str_replace("TypeOfEmployment", $arrayres["employment_type"], $content);
            $content = str_replace("TitleInOccupation", $arrayres["employment_occupation"], $content);
            $content = str_replace("BusinessName", $arrayres["employer_name"], $content);
            $content = str_replace("WorkPhone", $arrayres["employer_phone"], $content);
            $content = str_replace("IncomeAfterTax", $arrayres["income_aftertax"], $content);
            $content = str_replace("IncomeafterTaxPeriod", $arrayres["income_aftertax_period"], $content);
//liabilities
            $content = str_replace("Loanrepayment", $arrayres["liabilities_loanrepayment_payment"], $content);
            $content = str_replace("loanrepayment_paymentperiod", $arrayres["liabilities_loanrepayment_paymentperiod"], $content);
            $content = str_replace("Creditcard", $arrayres["liabilities_creditcard_payment"], $content);
            $content = str_replace("creditcard_paymentperiod", $arrayres["liabilities_creditcard_paymentperiod"], $content);
            $content = str_replace("Boardingrentingfee", $arrayres["liabilities_boardingrentingfee_payment"], $content);
            $content = str_replace("boardingrentingfee_paymentperiod", $arrayres["liabilities_boardingrentingfee_paymentperiod"], $content);
            $content = str_replace("Livingexpenses", $arrayres["liabilities_livingexpenses_payment"], $content);
            $content = str_replace("livingexpenses_payment", $arrayres["liabilities_livingexpenses_paymentperiod"], $content);
//credit
            $content = str_replace("Hardship", $arrayres["credit_hardship"], $content);
            $content = str_replace("CreditHistory", $arrayres["credit_history"], $content);
            $content = str_replace("DateOfDischarge ", $arrayres["credit_dischargedate"], $content);
            $content = str_replace("DefaultAfterDischarge", $arrayres["credit_discharge"], $content);
            $content = str_replace("totalOutstanding", $arrayres["credit_outstanding"], $content);
            echo $content;
        }
        ?>
    </body>
</html>